package org.nf.shopping.controller;

import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.nf.shopping.common.vo.ResultVO;
import org.nf.shopping.entity.Commodity;
import org.nf.shopping.service.CommodityService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author czl
 * @Date 2024-12-18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/commodity")
public class CommodityController extends BaseController{

    private final CommodityService commodityService;

    @GetMapping("/listCommodity")
    public ResultVO<PageInfo<Commodity>> listCommodity(Integer limit, Integer page, String name){
        PageInfo<Commodity> pageInfo = commodityService.listCommodity(limit, page, name);
        return success(pageInfo);
    }

    @PostMapping("/updateCommodity")
    public ResultVO updateCommodity(Commodity commodity){
        commodityService.updateCommodity(commodity);
        return success();
    }

    @PostMapping("/deloneCommodity")
    public ResultVO deloneCommodity(Integer id){
        commodityService.deloneCommodity(id);
        return success();
    }

    @PostMapping("/addCommodity")
    public ResultVO addCommodity(Commodity commodity){
        commodityService.addCommodity(commodity);
        return success();
    }

    @PostMapping("/getCommodityList")
    public ResultVO<List<Commodity>> getCommodityList(){
        return success(commodityService.getCommodityList());
    }
}
